﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TrabalhoLAP.Model.Class;

namespace TrabalhoLAP.DAO
{
    public class CategoriaDAO
    {
        public DataSet consultarCategoria(string drcCategoria, int codCategoria, int vlrCategoria, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;
            string sqlWhere = "";

            sql = "SELECT codCategoria, codAvaliacao, drcCategoria, vlrCategoria, statusRegistro FROM CATEGORIA ";

            if (!drcCategoria.Equals(""))
                sqlWhere = drcCategoria.Equals("") ? "" : "WHERE DrcCategoria LIKE '%" + drcCategoria + "%'";

            if (sqlWhere.Equals("") && codCategoria != 0 )
                sqlWhere = codCategoria.Equals("") ? "" : "WHERE CODCATEGORIA = " + codCategoria;
            else if ((!sqlWhere.Equals("")) && codCategoria != 0 )
                sqlWhere = codCategoria.Equals("") ? "" : " AND CODCATEGORIA = " + codCategoria;

            if (sqlWhere.Equals("") && vlrCategoria != 0 )
                sqlWhere = codCategoria.Equals("") ? "" : "WHERE vlrCategoria = " + vlrCategoria;
            else if ((!sqlWhere.Equals("")) && vlrCategoria != 0 )
                sqlWhere = codCategoria.Equals("") ? "" : " AND vlrCategoria = " + vlrCategoria;

            if (statusRegistro.Equals("0"))
            {
            }
            else if (sqlWhere.Equals(""))
                sqlWhere = "WHERE STATUSREGISTRO = '" + statusRegistro + "'";
            else
                sqlWhere += " AND STATUSREGISTRO = '" + statusRegistro + "'";

            sql = sql + sqlWhere;

            return acess.executeSelectQuery(sql);
        }

        public bool cadastrarCategoria(string DrcCategoria, int vlrCategoria, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;

            sql = "INSERT INTO CATEGORIA (codAvaliacao, drcCategoria, vlrCategoria, statusRegistro) VALUES(null, '" + DrcCategoria + "'," + vlrCategoria + ",'" + statusRegistro + "')";
            return acess.executeQuery(sql);
        }

        public bool alterarCategoria(int codCategoria, string DrcCategoria, int vlrCategoria, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;

            sql = "UPDATE USUARIO SET drcCategoria = '" + DrcCategoria + "', vlrCategoria = " + vlrCategoria + "statusRegistro = '" +  statusRegistro + "'";
            sql += " WHERE CODCATEGORIA = " + codCategoria;

            return acess.executeQuery(sql);
        }
    }
}